/*
 *  Copyright (c) 2014-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */

#import <ComponentKit/CKDefines.h>

#if CK_NOT_SWIFT

#import <ComponentKit/CKCompositeComponent.h>

NS_ASSUME_NONNULL_BEGIN

/**
 CKStatelessComponent is a component that can be represented with a pure
 function that takes props and returns component hierarchy. This component adds a
 string identifier to store the debug information about the calling function
 */
@interface CKStatelessComponent : CKCompositeComponent

CK_COMPOSITE_COMPONENT_INIT_UNAVAILABLE;

@property (nonatomic, readonly) NSString *identifier;

/**
 @param view Passed to CKComponent's initializer.
 @param component Result component hierarchy generated by the stateless functional component
 @param metadata The metadata to associated with the component.
 @param identifier Debug identifier of the stateless functional component.
 */
+ (nullable instancetype)newWithView:(const CKComponentViewConfiguration &)view component:(CKComponent *_Nullable)component metadata:(NSDictionary<NSString *, id> *_Nullable)metadata identifier:(NSString *)identifier;

/**
 @param view Passed to CKComponent's initializer.
 @param component Result component hierarchy generated by the stateless functional component
 @param identifier Debug identifier of the stateless functional component.
 */
+ (nullable instancetype)newWithView:(const CKComponentViewConfiguration &)view component:(CKComponent *_Nullable)component identifier:(NSString *)identifier;

@end

/**
 In debug this will allocate CKStatelessComponent with a given identifer
 Otherwise, will just return the passed component.
 NS_RELEASES_ARGUMENT because the argument is expected to be newly created, so
 we should save an objc_release of it in the caller.
 NS_RETURNS_RETAINED because we are transferring ownership of a newly-created
 object.

 @param component Result component hierarchy generated by the stateless functional component
 @param metadata The metadata to associated with the component.
 @param debugIdentifier Debug identifier of the stateless functional component.
 Always pass __func__ as an identifier
 */
CKComponent *_Nullable CKCreateStatelessComponent(NS_RELEASES_ARGUMENT CKComponent *_Nullable component, NSDictionary<NSString *, id> *_Nullable metadata, const char *debugIdentifier) NS_RETURNS_RETAINED;

CKComponent *_Nullable CKCreateStatelessComponent(NS_RELEASES_ARGUMENT CKComponent *_Nullable component, const char *debugIdentifier) NS_RETURNS_RETAINED;

NS_ASSUME_NONNULL_END

#endif
